package com.xy.controller

/**
  * Created by xiaoyuan on 2017/11/15.
  */
import java.util
import java.util.Date

import com.xy.domain.User
import com.xy.service.UserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.{RequestMapping, RequestParam, RestController}
import scala.collection.JavaConverters._

@RestController
class HelloController {

  @Autowired
  val userService:UserService =null;

  @RequestMapping(Array("/hello"))
  def greeting(@RequestParam(value="name", defaultValue="LightSword")  name: String) = {
    val now = new Date
    val content =  "Hello, " + name + "! Now is: " + now
    content

  }

  @RequestMapping(Array("/add"))
  def addUser(@RequestParam(value="name", defaultValue="LightSword")  name: String) = {
    //添加一个用户
    var user:User = new User
    user.setUserName("good")
    user.setPassword("123456")
    userService.add(user)
    //遍历userName为xy的用户
    var map = new util.HashMap[String,Object]
    map.put("userName","xy")
    var i=0
    var list = userService.queryLearnResouceList(map).asScala;
    list.foreach(x=>println(x.id+"-"+x.userName+"-"+x.password))
    "good"
  }

}